﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Content.Master" Inherits="System.Web.Mvc.ViewPage<cludg.Web.ViewModels.StoryDetailsModel>" %>

<%@ Import Namespace="cludg.Web.Core.RenderHelpers" %>
<%@ Import Namespace="cludg.Web.ViewModels" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
	<%: Model.Story.Title %>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<%
	bool userCanDeleteComment = Html.HasPermission("ManageComment");
%>

<script type="text/javascript">
	$(document).ready(
		function() {
			improveComments();
			validateCommentForm();
		}
	);
</script>

	<div class="story">
		<% Html.ViewExtensionPlace("Story_Show_Details_Before"); %>
		<% Html.RenderPartial("StoryDetailsControl", Model.Story); %>
		<% Html.ViewExtensionPlace("Story_Show_Details_After"); %>
		<% if (Model.ShowComments)
	 { %>
		<div class="comments">
			<h2>
				Комментарии</h2>
			<% Html.ViewExtensionPlace("Story_Show_Comments_Before"); %>
			<% foreach (var comment in Model.Story.FirstLevelComments.OrderBy(x => x.CreationTime))
	  { %>
			<%:Html.RenderTree(new CommentDetailsModel(comment, Model.CanAddComment, userCanDeleteComment))%>
			<% } %>
			<% if (Model.CanAddComment)
	  {%>
			<h3>
				<a href="#replay_0" onclick="setCommentForm(null);">Добавить комментарий</a></h3>
			<div id="replay_0">
				<div class='replayCommentForm'>
					<% Html.RenderPartial("CommentEditControl", new CommentModel { StoryId = Model.Story.Id }); %>
				</div>
			</div>
			<div id="commentForm" style="display: none;">
				<% Html.RenderPartial("CommentEditControl", new CommentModel { StoryId = Model.Story.Id }); %>
			</div>
			<%} else {%>
			<div class="comment-login-hint">
				Чтобы добавлять новые комментарии или отвечать на уже существующие, Вы должны 
				<%: Html.ActionLink("войти", "Login", "Account", null, null)%>
				или 
				<%: Html.ActionLink("зарегистрироваться", "Register", "Account", null, new { @class = "reg" })%>.
			</div>
			<%} %>
			<% Html.ViewExtensionPlace("Story_Show_Comments_After"); %>
		</div>
		<br />
		<div>
			<img src="/Content/images/rss-4.png" alt="RSS" />
			<span style = "vertical-align:middle;">
				<%: Html.ActionLink("RSS-подписка на комментарии", "CommentRss", "Feed",
					new RouteValueDictionary { { "id", Model.Story.Id } },
											null)%>
			</span>
		</div>
		<% } %>
	</div>
</asp:Content>
